<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>

<script>
    let arr = [{
        id: 5,
        name: 'jack',
        age: 21
    }, {
        id: 2,
        name: 'jack2',
        age: 21
    }, {
        id: 7,
        name: 'jack3',
        age: 21
    }];

    let result = arr.sort((x,y)=>{
        return x.id - y.id
    });

    console.log(result)

</script>
</body>

</html>
